package com.example.lenovo.downloaddemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.lenovo.downloaddemo.R;
import com.example.lenovo.downloaddemo.bean.SearchBean;
import com.example.lenovo.downloaddemo.http.okhttp.utils.AppContext;
import com.example.lenovo.downloaddemo.util.TextStyleLanguage;

import java.util.List;

public class SearchAdapter extends BaseAdapter {
    private Context context;
    private List<SearchBean.DataBean> data;

    public SearchAdapter(Context context,List<SearchBean.DataBean> data){
        this.context=context;
        this.data=data;

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view=LayoutInflater.from(AppContext.getInstance()).inflate(R.layout.search_item,null);
            holder.textView=(TextView) view.findViewById(R.id.search_name);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        if(data.size()>0) {
            if(!TextStyleLanguage.isEngLish()){
                holder.textView.setText(data.get(i).getGood_name());
            }else{
                holder.textView.setText(data.get(i).getGood_name_en());
            }

        }

        return view;
    }

    static  class  ViewHolder{
        TextView textView;
    }

}
